package com.leyou.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.leyou.common.vo.SpuItemAttrGroupVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.leyou.entity.SpecGroupEntity;
import com.leyou.service.SpecGroupService;

import com.leyou.api.R;



/**
 * 规格参数的分组表，每个商品分类下有多个规格参数组
 *
 * @author Daifeng
 * @email 2661184062@qq.com
 * @date 2020-12-25 16:44:47
 */
@RestController
@RequestMapping("/specgroups")
public class SpecGroupController {
    @Autowired
    private SpecGroupService specGroupService;


    @GetMapping("/GroupAttrByCid/{cid}")
    private R getGroupAttrByCid(@PathVariable("cid") Long cid){
        List<SpuItemAttrGroupVo> groupVos =  specGroupService.getGroupAttrByCid(cid);
        return R.ok().put("data",groupVos);
    }


    @GetMapping("/list/{cid}")
   private R listByCid(@PathVariable Long cid){
       List<SpecGroupEntity> groupEntities =  specGroupService.listByCid(cid);
       return R.ok().put("data",groupEntities);
   }



    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
 //   @RequiresPermissions("leyou:specgroup:info")
    public R info(@PathVariable("id") Long id){
		SpecGroupEntity specGroup = specGroupService.getById(id);

        return R.ok().put("specGroup", specGroup);
    }

    /**
     * 保存
     */
    @PostMapping("/addspec")
    public R save(@RequestBody SpecGroupEntity specGroup){
		specGroupService.save(specGroup);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/addspec")
    public R update(@RequestBody SpecGroupEntity specGroup){
		specGroupService.updateById(specGroup);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
   // @RequiresPermissions("leyou:specgroup:delete")
    public R delete(@PathVariable Long id){
        boolean b = specGroupService.deleteSpec(id);
        if(b){
            return R.ok();
        }else {
            return R.error().put("key","该分组下还有属性信息,暂不能删除！");
        }

    }

}
